package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.entity.Category;
import com.situ.mall.entity.CategoryCount;
import com.situ.mall.entity.Result;
import com.situ.mall.mapper.CategoryMapper;
import com.situ.mall.service.ICategoryService;

@Service
public class CategoryServiceImpl implements ICategoryService{
	@Autowired
	private CategoryMapper categoryMapper;

	@Override
	public List<Category> selectTopCategoryList() {
		return categoryMapper.selectTopCategoryList();
	}

	@Override
	public List<Category> selectSecondCategoryByTopCategoryId(Integer topCategoryId) {
		return categoryMapper.selectSecondCategoryByTopCategoryId(topCategoryId);
	}

	@Override
	public List<Category> selectSecondCategoryList() {
		return categoryMapper.selectSecondCategoryList();
	}

	@Override
	public List<CategoryCount> getCategoryCount() {
		return categoryMapper.getCategoryCount();
	}

	@Override
	public Result selectByPage(Integer page, Integer limit, Category category) {
		// 查询一种有多少调数据
		int count = categoryMapper.getTotalCount(category);
		// 当前页数据
		int offset = (page -1 ) * limit;
		List<Category> list = categoryMapper.selectByPage(offset, limit, category);
		return Result.success("", list, count);
	}
	@Override
	public boolean deleteAll(Integer[] ids) {
		int count =0;
		for (Integer id : ids) {
			int c=categoryMapper.deleteByPrimaryKey(id);
			count+=c;
		}
		return count==ids.length ?true : false;
	}
	@Override
	public boolean deleteById(Integer id) {
		int count=categoryMapper.deleteByPrimaryKey(id);
		return count == 1 ? true : false;
	}
	@Override
	public boolean insert(Category category) {
		category.setParentId(0);
		int count=categoryMapper.insert(category);
		return count == 1 ? true : false;
	}
	@Override
	public boolean insert2(Category category) {
		int count=categoryMapper.insert(category);
		return count == 1 ? true : false;
	}

}